
import java.io.FileInputStream;
import java.nio.charset.Charset;
import java.sql.*;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.Transaction;
import sunsite.po.Datadic;
import sunsite.po.DatadicType;
import sunsite.po.University;
import sunsite.po.Usr;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Ruby
 */
public class Test
{
    static
    {
//        org.apache.log4j.PropertyConfigurator.configure("pp");
    }
    public static org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(Test.class);

    public static void main(String[] agrs) throws Exception
    {
//        FileInputStream fi = new FileInputStream("log4j.properties");
//        logger.info("error2");

        try
        {
            Class.forName("com.mysql.jdbc.Driver");
            Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/sunsite", "root", "123");
            Statement stmt = con.createStatement();
//            stmt.executeUpdate("insert into datadic values (14,2,'中文')");

        }
        catch(Exception err)
        {
            System.out.println(err);
        }
//        if (true)
//        {
//            return;
//        }
        Session session = HibernateUtil.getSessionFactory().openSession();
        Transaction trac = session.beginTransaction();
        List users = session.createCriteria(Usr.class).list();// get(Usr.class, "123456");
        for(Object user : users)
        {
            ((Usr)user).setPassword(sunsite.tools.MD5.toMD5("123"));
            session.save(user);
        }
        trac.commit();
//        user.setDegree("xx中文");
//        session.update(user);
//        trac.commit();
//        Usr user2 = (Usr)session.get(Usr.class, "123456");
//        System.out.println(user2.getDegree());
//        DatadicType dt = (DatadicType)session.get(DatadicType.class, 1);
//        Datadic dd = (Datadic) session.get(Datadic.class, 11);
//        System.out.println(dt.getDatadic());
//        System.out.println(dd.getDicValue());

    }
}
